<?php
/**
 * @author spenceryg
 * @date 2023/3/28
 * @time 7:06 上午
 * @focus love & life
 */


namespace app\api\controller;

use app\BaseController;
use app\common\model\MemberFile;
use app\common\model\PushLog;
use app\common\model\PushPlan;
use hg\apidoc\annotation as Apidoc;
use app\common\model\ArticleContent;
use app\common\model\GptRequestLog;
use app\common\model\GptStrategy;
use app\common\model\GptToken;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Pool;
use GuzzleHttp\Psr7\Response;
use think\facade\Db;



class TestGptKey extends BaseController
{
    public function test(){

        $client = new Client();


        $token_key='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';
        $response = $client->post('https://api.openai.com/v1/chat/completions', [
            'headers' => [
                'Authorization' => 'Bearer '.$token_key,
                'Content-Type' => 'application/json',
            ],
            'json' => [
                'model' => 'gpt-3.5-turbo',
                'messages' => [
                    [
                        "role" => "user",
                        "content" => "你好"
                    ],
                ],
                //'max_tokens' => 3600,//这里不要限制token否则当输入的token比较多的时候会报错
            ]
        ]);
        $data = json_decode($response->getBody(), true);
        print_r($data);exit;


    }

}
